package org.example.exp2;

import org.example.exp2.entity.Book;
import org.example.exp2.entity.Person;
import org.example.exp2.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;



@SpringBootApplication
public class Exp2Application {

    public static void main(String[] args) {
        SpringApplication.run(Exp2Application.class, args);

        ApiService apiService = new ApiService(WebClient.builder());

//        // 调用GET API并期望JSON响应
//        String jsonResponse = apiService.callGetApi("/books", MediaType.APPLICATION_JSON);
//        System.out.println("JSON Response: " + jsonResponse);
//
//        // 调用GET API并期望XML响应
//        String xmlResponse = apiService.callGetApi("/books", MediaType.APPLICATION_XML);
//        System.out.println("XML Response: " + xmlResponse);
//
//        String grResponse = apiService.callGetApi("/books", MediaType.APPLICATION_GRAPHQL_RESPONSE);
//        System.out.println("GRAPHQL Response: " + grResponse);

//        String xmlResponse = apiService.callGetApi("/persons",MediaType.APPLICATION_XML);
//        System.out.println("XML Response: "+xmlResponse);
//
//        String grResponse = apiService.callGetApi("/persons",MediaType.APPLICATION_GRAPHQL_RESPONSE);
//        System.out.println("GRAPHQL Response: "+grResponse);
//
//        String jsonResponse = apiService.callGetApi("/persons",MediaType.APPLICATION_JSON);
//        System.out.println("JSON Response: "+ jsonResponse);
//
//        // 调用GET API并期望JSON响应
//        String getJsonResponse = apiService.callGetApi("/books/1", MediaType.APPLICATION_JSON);
//        System.out.println("GET JSON Response: " + getJsonResponse);
//
        // 调用POST API并期望JSON响应
//        Book request = new Book();
//        request.setTitle("标题1");
//        request.setAuthor("作者1");
//        request.setIsbn("12345");
//        request.setAvailable(true);
//        String postJsonResponse = apiService.callPostApi("/books", request, MediaType.APPLICATION_JSON);
//        System.out.println("POST JSON Response: " + postJsonResponse);

//        Person request = new Person();
//        request.setName("张三");
//        request.setAge(20);
//        request.setEmail("123444555@qq.com");
//        String postJsonResponse = apiService.callPostApi("/persons",request,MediaType.APPLICATION_JSON);
//        System.out.println("POST JSON Response: " + postJsonResponse);
//
//        // 调用PUT API并期望JSON响应
//        request.setTitle("标题2");
//        request.setAvailable(false);
//        String putJsonResponse = apiService.callPutApi("/books/4", request, MediaType.APPLICATION_JSON);
//        System.out.println("PUT JSON Response: " + putJsonResponse);
//
//        // 调用DELETE API并期望JSON响应
//        String deleteJsonResponse = apiService.callDeleteApi("/books/9", MediaType.APPLICATION_JSON);
//        System.out.println("DELETE JSON Response: " + deleteJsonResponse);

//          String deleteJsonResponse = apiService.callDeleteApi("/persons/5",MediaType.APPLICATION_JSON);
//        System.out.println("DELETE JSON Response: "+ deleteJsonResponse);


    }

}
